﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Net;

using EHTWebsite.Code;
using EHTWebsiteProject.Code.BLL;
using System.Resources;
using System.Threading;
using System.Globalization;
using System.Text;

namespace EHTWebsiteProject.Administrator
{
    public partial class EHTDichVu : System.Web.UI.Page
    {
        public Boolean IsVN = true;
        private String languageCode = "vi-VN";
        private String message = "";
        private ResourceManager rm = new ResourceManager("Resources.SiteMap", System.Reflection.Assembly.Load("App_GlobalResources"));

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                AjaxPro.Utility.RegisterTypeForAjax(typeof(EHTWebsiteProject.Administrator.EHTDichVu));

                try
                {
                    languageCode = Session[HangSo.LANGUAGE_CODE].ToString();
                    Session["NgonNgu"] = languageCode;
                    if (languageCode == "en-us")
                    {
                        IsVN = false;
                    }

                }
                catch (Exception ex)
                {
                }
                try
                {
                    message = Request.QueryString["Message"].ToString();
                    if (message != "")
                        ltrErorr.Text = HelpMethod.ApplySuccess(message);
                }
                catch
                {

                }
                Thread.CurrentThread.CurrentCulture = new CultureInfo(languageCode);
                LoadLanguage(Thread.CurrentThread.CurrentCulture);
                LoadDichVu();
            }
        }

        /// <summary>
        /// Ham load ngon ngu
        /// </summary>
        /// <param name="ci"></param>
        public void LoadLanguage(CultureInfo ci)
        {
            lbDichVu.Text = rm.GetString("lbDichVu", ci);           
            lbHelp.Text = rm.GetString("lbHelp", ci);
            lbSave.Text = rm.GetString("lbSave", ci);
            lbThongTinCongTy.Text = rm.GetString("lbThongTinCongTy", ci);
            lbHoTro.Text = rm.GetString("lbHoTro", ci);
            lbDichVuVN.Text = rm.GetString("lbDichVuVN", ci);
            lbDichVuOther.Text = rm.GetString("lbDichVuOther", ci);
            lbHinhANhCongTy.Text = rm.GetString("lbHinhANhCongTy", ci);
        }

        [AjaxPro.AjaxMethod]
        public void LoadDichVu()
        {
            ThongTinCongTy theThongTin = ThongTinCongTyProvider.GetThongTinCongTyByCongTyID(HangSo.COMPANY_ID);           
            if (theThongTin.DichVuTomTatVN != "")
                RadNoiDUngVN.Content =  theThongTin.DichVuTomTatVN + "-------" + theThongTin.DichVuVN;
            else
                RadNoiDUngVN.Content = theThongTin.GioiThieuVN;
            if (theThongTin.DichVuTomTatOther != "")
                RadNoiDungOther.Content =theThongTin.DichVuTomTatOther + "-------" + theThongTin.DichVuOther;
            else
                RadNoiDungOther.Content = theThongTin.GioiThieuOther;

        }

        protected void ImgSave_Click(object sender, ImageClickEventArgs e)
        {
            ThongTinCongTy theThongTin = new ThongTinCongTy();
            int index1 = RadNoiDungOther.Content.IndexOf("------");
            int index2 = RadNoiDUngVN.Content.IndexOf("------");
            try
            {
                theThongTin.DichVuTomTatOther = RadNoiDungOther.Content.Substring(0, index1).ToString();
                theThongTin.DichVuOther = RadNoiDungOther.Content.Remove(0, index1 + 7).ToString();
            }
            catch
            {
                theThongTin.DichVuTomTatOther = "";
                theThongTin.DichVuOther = RadNoiDungOther.Content;
            }

            try
            {
                theThongTin.DichVuTomTatVN = RadNoiDUngVN.Content.Substring(0, index2).ToString();
                theThongTin.DichVuVN = RadNoiDUngVN.Content.Remove(0, index2 + 7).ToString();
            }
            catch
            {
                theThongTin.DichVuTomTatVN = "";
                theThongTin.DichVuVN = RadNoiDUngVN.Content;
            }

            ThongTinCongTyProvider.UpdateDichVuByCongTyID(theThongTin.DichVuVN, theThongTin.DichVuOther, theThongTin.DichVuTomTatVN, theThongTin.DichVuTomTatOther, HangSo.COMPANY_ID);
            String str = "";
            if (IsVN == true)
                str = HangSo.App_VN;
            else
                str = HangSo.App_Other;
            Response.Redirect("EHTDichVu.aspx?Message=" + str);
        }
    }
}